﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace IndirectX.Windows
{
    public delegate void MainLoop();

    public class MessagePump
    {
        public static void Run(RenderForm form, MainLoop mainLoop)
        {
            Application.Idle += new EventHandler(new MessagePump.IdleHandler(mainLoop).OnIdle);
            Application.Run(form);
        }


        private class IdleHandler
        {
          private MainLoop loopDelegate;

          public IdleHandler(MainLoop mainLoop)
          {
            this.loopDelegate = mainLoop;
          }

          public void OnIdle(object sender, EventArgs e)
          {
            //tagMSG tagMsg;
            //while (Module.PeekMessageW(&tagMsg, (HWND__*) 0, 0U, 0U, 0U) == 0)
              this.loopDelegate();
          }
        }
    }
}
